package com.yww.player

import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.yww.player.databinding.ActivityVideoListBinding

class VideoListActivity : AppCompatActivity() {
    private val TAG = "VideoListActivity"
    private var mAdapter: VideoListAdapter? = null
    private val viewModel: VideoListViewModel by viewModels()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding: ActivityVideoListBinding =
            DataBindingUtil.setContentView(this@VideoListActivity, R.layout.activity_video_list)
        binding.apply {
            rvVideoList.layoutManager = LinearLayoutManager(baseContext)
            mAdapter = VideoListAdapter()
            rvVideoList.adapter = mAdapter
            viewModel.mVideoList.observe(this@VideoListActivity) {
                if (it.isNotEmpty()) {
                    Log.d(TAG, "observe: 更新了数据")
                    mAdapter?.update(it)
                }
            }
        }
        viewModel.searchVideo(this@VideoListActivity)
    }
}